﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PiaoanWeb.AppLogic.BusinessLogicLayer;
using PiaoanWeb.AppLogic.DataAccessLayer;
using PiaoanWeb.Helpers;
namespace PiaoanWeb.Admin
{
    public partial class AddProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CategoriesBLL categoryBLL = new CategoriesBLL();
                categoryDDL.DataSource = categoryBLL.GetAllCategoriesExcludeDeleted();
                categoryDDL.DataBind();
            }
        }

        protected void saveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                ProductsBLL productsBLL = new ProductsBLL();
                Products product = new Products();
                product.IsDeleted = false;
                product.CategoryID = Convert.ToInt32(categoryDDL.SelectedValue);
                product.Description = descriptionTxtbox.Text;
                product.Name = nameTxtBox.Text;
                product.ProductImage = "NoImage.jpg";
                product.PublishDate = DateTime.Now;
                productsBLL.AddProduct(product);

                Response.Redirect("ProductList.aspx");
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                msgLbl.Text = "添加产品失败，请联系管理员："+ex.Message;
            }
        }

        protected void cancelBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("ProductList.aspx");
        }
    }
}